package com.study.amqp_2;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import com.rabbitmq.client.AMQP.BasicProperties;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * 使用amqp-client发布消息和订阅消息
 *
 */
public class Product {
	public static void main(String[] args) throws IOException, TimeoutException {

		ConnectionFactory factory = new ConnectionFactory();
		factory.setHost("127.0.0.1");
		factory.setPort(5672);
		factory.setUsername("guest");
		factory.setPassword("guest");
		factory.setVirtualHost("log");

		Connection conn = factory.newConnection();
		Channel channel = conn.createChannel();

		// TODO 發佈消息
		BasicProperties props = new BasicProperties().builder().deliveryMode(2).contentEncoding("UTF-8").build();
		channel.basicPublish("user_exchange", "user", props, "aqmp-client 发送".getBytes());
		

		channel.close();
		conn.close();

	}
}
